//
//  PaidOrderInfoViewController.m
//  HTP
//
//  Created by 王鑫 on 15/11/13.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "PaidOrderInfoViewController.h"
#import "MyOrderViewModel.h"

@interface PaidOrderInfoViewController ()

@property (nonatomic, retain) UIImageView *topTextImage;

@property (nonatomic, retain) UIImageView *topIcoImage;

@property (nonatomic, retain) UIImageView *topVIew;

@property (nonatomic, retain) UILabel *orderIDLabel;

@property (nonatomic, retain) UILabel *teacherNameLabel;

@property (nonatomic, retain) UILabel *priceLabel;

@property (nonatomic, retain) UILabel *teachNumberLabel;

@property (nonatomic, retain) UILabel *creatTimeLabel;

@property (nonatomic, retain) UILabel *moneyLabel;

@property (nonatomic, retain) UILabel *payTimeLabel;

@property (nonatomic, retain) MyOrderModel *myOrderM;

@property (nonatomic, retain) MyOrderViewModel *myOrderVM;

@end

@implementation PaidOrderInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
    [self getMyOrderDetail];
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self addCustomBackBase];
    [self addCustomTitleWithTitle:@"订单详情"];
}

//TODO:UI绘制 -- wangxin
- (void)initUI{
    _topVIew = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 130)];
    _topVIew.image = [UIImage imageNamed:@"fukuanbg"];
    [self.view addSubview:self.topVIew];
    
    _topTextImage = [[UIImageView alloc] initWithFrame:CGRectMake(55, 50, 110, 40)];
    [_topVIew addSubview:self.topTextImage];
    
    _topIcoImage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth - 110, 10, 70, 110)];
    [_topVIew addSubview:self.topIcoImage];
    
    UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(0, 130, ScreenWidth, 1)];
    line.image = [UIImage imageNamed:@"line"];
    [line setAlpha:0.6];
    [self.view addSubview:line];
    
    _orderIDLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 150, 240, 25)];
    _orderIDLabel.font = [UIFont systemFontOfSize:16.0f];
    [self.view addSubview:self.orderIDLabel];
    
    _teacherNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 180, 240, 25)];
    _teacherNameLabel.font = [UIFont systemFontOfSize:16.0f];
    [self.view addSubview:self.teacherNameLabel];
    
    _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 210, 240, 25)];
    _priceLabel.font = [UIFont systemFontOfSize:16.0f];
    [self.view addSubview:self.priceLabel];
    
    _teachNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 240, 240, 25)];
    _teachNumberLabel.font = [UIFont systemFontOfSize:16.0f];
    [self.view addSubview:self.teachNumberLabel];
    
    _creatTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 270, 240, 25)];
    _creatTimeLabel.font = [UIFont systemFontOfSize:16.0f];
    [self.view addSubview:self.creatTimeLabel];
    
    _moneyLabel = [self getNormolLabel];
    [_moneyLabel setFrame:CGRectMake(0, 350, 470, 20)];
    [_moneyLabel setFont:[UIFont systemFontOfSize:20]];
    [self.view addSubview:self.moneyLabel];
    
    _payTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 300, 240, 25)];
    _payTimeLabel.font = [UIFont systemFontOfSize:16.0f];
    [self.view addSubview:self.payTimeLabel];
}

//数据获取
- (void)getMyOrderDetail {
    MyOrderViewModel *myOderVM = [[MyOrderViewModel alloc] init];
    [myOderVM setBlockWithReturnBlock:^(id returnValue) {
        [self hiddenMbProgress];
        [self getData:(NSDictionary *)returnValue];
        [self setData];
    } WithErrorBlock:^(id errorCode) {
        [self hiddenMbProgress];
    } WithFailureBlock:^{
        [self hiddenMbProgress];
    }];
    [self showMbProgress:@""];
    [myOderVM getOrderDetailByOrderId:_orderId];
}

//字典 - 》 模型
- (void)getData:(NSDictionary *)message {
    DLog(@"%@",message[INTERFACE_INFO]);
    _myOrderM = [MyOrderModel mj_objectWithKeyValues:message[INTERFACE_INFO]];
}

//数据设置
- (void)setData {
    
    _payTimeLabel.text     = [NSString stringWithFormat:@"付款时间 : %@",_myOrderM.ordTime];
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"￥%.2lf",[_myOrderM.ordValue floatValue]]];
    NSInteger length = [NSString stringWithFormat:@"￥%.2lf",[_myOrderM.ordValue floatValue]].length;
    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 1)];
    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(1, length - 3)];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(1, length - 1)];
    _moneyLabel.attributedText = str;
    
    _creatTimeLabel.text   = [NSString stringWithFormat:@"创建时间 : %@",_myOrderM.ordCreatTime];
    _teachNumberLabel.text = [NSString stringWithFormat:@"上课次数 : %@",_myOrderM.ordCourseTime];
    _priceLabel.text       = [NSString stringWithFormat:@"单价 : %@元/h",_myOrderM.ordSinglePrice];
    _teacherNameLabel.text = [NSString stringWithFormat:@"教师 : %@",_myOrderM.teacherName];
    _orderIDLabel.text     = [NSString stringWithFormat:@"订单编号 : %@",_myOrderM.ordCode];
    
    _topTextImage.image = [UIImage imageNamed:@"yifukuan"];
    [_topIcoImage setFrame:CGRectMake(ScreenWidth - 130, 10, 110, 110)];
    _topIcoImage.image = [UIImage imageNamed:@"gantanhao"];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
